
# Installation Dirs
PREFIX ?= $(DESTDIR)/usr
LIBDIR ?= $(PREFIX)/lib
SHLIBDIR ?= $(DESTDIR)/lib

# Needed Programs
AR=$(PREFIX)/bin/ar
RANLIB=$(PREFIX)/bin/ranlib

LIBVER=1

LIBA:=libmmh.a
TARGET:=libmmh.so
LIBSO:=$(TARGET).$(LIBVER)

OBJS=$(patsubst %.c, %.o, $(wildcard *.c))
LOBJS=$(patsubst %.c, %.lo, $(wildcard *.c))

CFLAGS ?= -Wall -W -Wundef -Wmissing-noreturn -Wmissing-format-attribute
override CFLAGS += -I. -I../include -D_GNU_SOURCE

all: $(LIBA) $(LIBSO)

$(LIBA): $(OBJS)
	$(AR) rcs $@ $^
	$(RANLIB) $@

$(LIBSO): $(LOBJS)
	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -Wl,-soname,$(LIBSO),-z,defs
	ln -sf $@ $(TARGET)

%.o: %.c
	$(CC) $(CFLAGS) -fPIC -c -o $@ $^

%.lo: %.c
	$(CC) $(CFLAGS) -fPIC -DSHARED -c -o $@ $^

install: all
	test -d $(LIBDIR) || install -m 755 -d $(LIBDIR)
	install -m 644 $(LIBA) $(LIBDIR)
	test -d $(SHLIBDIR) || install -m 755 -d $(SHLIBDIR)
	install -m 755 $(LIBSO) $(SHLIBDIR)
	cd $(SHLIBDIR) && ln -sf ../../`basename $(SHLIBDIR)`/$(LIBSO) $(TARGET)

clean: 
	rm -f $(OBJS) $(LOBJS) $(TARGET) $(LIBSO) $(LIBA)

uninstall:
	rm -f $(LIBDIR)/$(LIBA) $(SHLIBDIR)/$(LIBSO) ../../`basename $(SHLIBDIR)`/$(TARGET) 

indent:
	../utils/Lindent $(wildcard *.[ch])




